﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace SMS
{

    public partial class fQuanlykhachhang : Form
    {

        fLogin main;
        public fQuanlykhachhang(fLogin main1)
        {
            InitializeComponent();
            main = main1;
        }

        // Khu vực chứa các function hỗ trợ
        SqlDataAdapter adapter;
        SqlConnection conn;
        SqlCommand command;


        public bool KiemTraThongTinImport()
        {
            return true;
        }

        public void ImportToDB()
        {

        }

        public DataTable LayDanhSachKH()
        {
            return null;
        }

        public DataRow LayChiTietKH(string MaKH)
        {
            return null;
        }

        // Kết thúc khu vực chứa các function hỗ trợ


        public void fQuanlykhachhang_Load(object sender, EventArgs e)
        {
            panel2.Controls.Add(main.Themkhachhang);
            main.Themkhachhang.Show();
            panel2.Controls.Add(main.Importkhachhang);
            main.Importkhachhang.Show();
            panel2.Controls.Add(main.Danhsachkhachhang);
            main.Danhsachkhachhang.Show();

            main.Danhsachkhachhang.Visible = false;
            main.Importkhachhang.Visible = false;
            main.Themkhachhang.Visible = false;
            pictureBox1.Visible = true;
            cboTimKiemTheo.Enabled = false;
            txtTuKhoa.Enabled = false;
            bntTim.Enabled = false;
        }


        private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.Visible = true;

        }

        private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
        {

            main.DoiMatKhau.Visible = true;
        }

        private void bntThemMoiTTKH_Click_1(object sender, EventArgs e)
        {
            main.Themkhachhang.Visible = true;
            main.Danhsachkhachhang.Visible = false;
            main.Importkhachhang.Visible = false;

            //Themmoikhachhang.BringToFront();
            pictureBox1.Visible = false;
            cboTimKiemTheo.Enabled = false;
            txtTuKhoa.Enabled = false;
            bntTim.Enabled = false;
            main.Themkhachhang.uThemMoiKhachHang_Load(null,null);
        }

        private void btnImportDanhSachKhachHang_Click_1(object sender, EventArgs e)
        {
            main.Danhsachkhachhang.Visible = false;
            main.Importkhachhang.Visible = true;
            main.Themkhachhang.Visible = false;
            //Importthongtinkhachhang.BringToFront();
            pictureBox1.Visible = false;
            cboTimKiemTheo.Enabled = false;
            txtTuKhoa.Enabled = false;
            bntTim.Enabled = false;
            main.Importkhachhang.dataGridView1.DataSource = null;
            main.Importkhachhang.txtImport.ResetText();
            main.Importkhachhang.bntSave.Enabled = false;
            //main.Importkhachhang.uim
        }

        private void btnXemDanhSachKhachHang_Click_1(object sender, EventArgs e)
        {
            main.Importkhachhang.Visible = false;
            main.Danhsachkhachhang.Visible = true;
            main.Themkhachhang.Visible = false;
            //main.Danhsachkhachhang.BringToFront();
            pictureBox1.Visible = false;
            cboTimKiemTheo.Enabled = true;
            txtTuKhoa.Enabled = true;
            bntTim.Enabled = true; ;
            cboTimKiemTheo.SelectedIndex= 0;
            main.Danhsachkhachhang.uDanhsachkhachhang_Load(null, null);
        }

        private void bntVeGiaoDienChinh_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            main.HeThong.Visible = true;
        }

        private void txtDangxuat_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.Visible = true;
        }

        private void lnkDoiMatKau_Click(object sender, EventArgs e)
        {
            main.DoiMatKhau.Visible = true;
        }


        private void tsmiQuanLyXe_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.QuanLyXe.Visible = true;
            main.QuanLyXe.fQuanlyxe_Load(null, null);
        }

        private void tsmiQuanLyTinNhan_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.QuanLyTinNhan.fQuanlytinnhan_Load(null, null);
            main.QuanLyTinNhan.Visible = true;
        }

        private void ttQuanlytaikhoan_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.QuanLyTaiKhoan.Visible = true;
            main.QuanLyTaiKhoan.FQuanlytaikhoan_Load_1(null, null);
        }

        private void picExit_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.Visible = true;
        }

        private void calendarToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void calculatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc");
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void bntTim_Click(object sender, EventArgs e)
        {

        }
        int i = 1;
        private void txtTuKhoa_TextChanged(object sender, EventArgs e)
        {

            DataTable dtbResult = new DataTable();
            conn = new SqlConnection(main.ConnectDB);
            command = new SqlCommand();
            command.Connection = conn;
            adapter = new SqlDataAdapter(command);
            if (i == 1)
            {
                command.CommandText = "SELECT HOTEN, KH.CMND , COUNT(XE.SOKHUNG) AS '" + " SO XE DA MUA" + "' FROM KHACHHANG KH, XEMAY XE" +
                                " WHERE XE.CMND = KH.CMND and tinhtrang='" + "yes" + "' and HOTEN like '%'+@ten+'%'" +
                                "  GROUP BY HOTEN, KH.CMND";
                //command.CommandText = "SELECT HOTEN, CMND From KHACHHANG where HOTEN like @ten +'%'";
                command.Parameters.Add(new SqlParameter("@ten", txtTuKhoa.Text.ToString()));
            }
            else if (i == 2)
            {
                command.CommandText = "SELECT HOTEN, KH.CMND , COUNT(XE.SOKHUNG) AS '" + " SO XE DA MUA" + "' FROM KHACHHANG KH, XEMAY XE" +
                                " WHERE XE.CMND = KH.CMND and tinhtrang='" + "yes" + "' and KH.CMND like '%'+@cmnd +'%'" +
                                "  GROUP BY HOTEN, KH.CMND";
                //command.CommandText = "SELECT HOTEN, CMND From KHACHHANG where CMND like @cmnd +'%'";
                command.Parameters.Add(new SqlParameter("@cmnd", txtTuKhoa.Text.ToString()));
            }


            //command.CommandText = "SELECT HOTEN, CMND From KHACHHANG where HOTEN like @ten +'%'";

            try
            {


                adapter.Fill(dtbResult);

            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
           
            main.Danhsachkhachhang.dgvDSKH.DataSource = dtbResult;





        }

        private void cboTimKiemTheo_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (cboTimKiemTheo.Text == "Tên khách hàng")
            {
                i = 1;
                txtTuKhoa.ResetText();
            }
            if (cboTimKiemTheo.Text == "Số CMND")
            {
                i = 2;
                txtTuKhoa.ResetText();

            }
        }

        private void viewHelpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                //Process k = new Process();
                //k.StartInfo.FileName = "C:\\Users\\PHUNGUYEN\\Desktop\\Year 3\\PM\\New folder\\SMS\\SMS\\PoD.doc";
                //k.StartInfo.Arguments = "";
                //k.Start();
                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                string currentDir = Environment.CurrentDirectory;//lấy đường dẫn thư mục hiện tại.
                prc.StartInfo.FileName = currentDir + "\\PoD\\User Guide SMS_SYSTEM.pdf";
                prc.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không thể mở file!");
            }
        }

        private void aboutRestaurantSystemManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                string currentDir = Environment.CurrentDirectory;//lấy đường dẫn thư mục hiện tại.
                prc.StartInfo.FileName = currentDir + "\\PoD\\PoD.html";
                prc.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không thể mở file!");
            }
        }


        //




    }
}












